/**
 * @author zhoushengtao
 * @since 2012-8-23 下午4:00:25
 */

package com.stchou.superbrowser.ui.widget;

import com.stchou.superbrowser.ui.animation.ComposerButtonGrowAnimationIn;
import com.stchou.superbrowser.ui.animation.InOutAnimation;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageButton;

public class SuperImageButton extends ImageButton
{
    private Animation animation;
    private Animation m_growInAnimation = new ComposerButtonGrowAnimationIn(500);
    private String m_ButtonTextString;

    @Override
    protected void onAnimationStart()
    {
        super.onAnimationStart();
        if ((this.animation instanceof InOutAnimation))
            setVisibility(View.VISIBLE);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_UP:
                startAnimation(m_growInAnimation);
                break;
            case MotionEvent.ACTION_OUTSIDE:
                break;
            default:
                break;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public void startAnimation(Animation animation)
    {
        super.startAnimation(animation);
        this.animation = animation;
        getRootView().postInvalidate();
    }

    public SuperImageButton(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public SuperImageButton(Context context)
    {
        super(context);
    }

    public void setText(String text)
    {
        m_ButtonTextString = text;
    }

    public String getText()
    {
        return m_ButtonTextString;
    }

}
